package com.vrv.netmgr.service;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.util.Log;

import com.vrv.common.GlobalConstants;
import com.vrv.common.util.CheckNetStatus;
import com.vrv.netmgr.EdpApplication;
import com.vrv.netmgr.database.downservice.AlarmStatisticsDown;
import com.vrv.netmgr.database.downservice.EquipmentChangedDown;
/**
 * 探测服务器是否在线
 * @author zxb
 *
 */
public class HeartService extends Service {
	private static final String TAG = HeartService.class.getSimpleName();
	private static final boolean DEBUG = true && GlobalConstants.DEBUG;
	
	private Handler mHandler;
	
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		if (DEBUG) Log.e(TAG, "onCreate()");
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		if (DEBUG) Log.e(TAG, "onStartCommand()");

		HandlerThread handlerThread = new HandlerThread("cachethread");
		handlerThread.start();
		mHandler = new Handler(handlerThread.getLooper());
		mHandler.post(mRunnable);

		return super.onStartCommand(intent, flags, startId);
	}
	
	private Runnable mRunnable = new Runnable() {
		@Override
		public void run() {
			if (DEBUG) Log.e(TAG, "mRunnable.run()");

            boolean bWifi = false;
            boolean bServer = false;
            
        	//探测wifi
            bWifi = CheckNetStatus.detectWifi();
            
            if (bWifi) {
            	//探测服务器
            	bServer = CheckNetStatus.detectServer();
    		}
        	
        	boolean status = bWifi & bServer;
        	
        	EdpApplication.setNetStatus(status);
		}
	};
}
